<template>
  <el-dialog :visible="settingsVisible" :title="myIndex > -1? '编辑'+titleName : '新增'+titleName" width="40%" @close="closeDialog">
    <!-- 新增环节 -->
    <el-form v-if="settingMode === 'addStep'" ref="addStep" :rules="rule" :model="settingForm">
      <el-form-item :label-width="labeWidth" label="环节名称" prop="linkName">
        <el-col :span="18" >
          <el-input v-model="settingForm.linkName" maxlength="10" placeholder="请填写环节名称"/>
        </el-col>
      </el-form-item>
      <el-form-item :label-width="labeWidth" label="说明" prop="description">
        <el-col :span="18" >
          <el-input v-model="settingForm.description" type="textarea" maxlength="100"/>
        </el-col>
      </el-form-item>
      <div class="bottomBtn">
        <el-button type="primary" @click="submitForm('addStep')">确定</el-button>
        <el-button type="info" @click="closeDialog">取消</el-button>
      </div>
    </el-form>
  </el-dialog>
</template>

<script>
import { Message } from 'element-ui'
import { vipInfoAll } from '@/api/product'
// <sendGoods :send-goods-visible.sync="sendGoods" :send-goods-index="sendGoodsIndex" :send-goods-id="sendGoodsId"/>
export default {
  props: {
    settingsVisible: {
      type: Boolean,
      required: true
    },
    myIndex: {
      type: Number,
      required: true
    },
    dialogData: {
      type: Object,
      required: true
    },
    settingMode: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      labeWidth: '80px',
      goodTypesForm: {},
      settingForm: {},
      tinymceDis: false,
      discountList: [],
      momList: [],
      rule: {
        linkName: [
          { required: true, message: '请填写环节名称', trigger: 'blur' }
        ],
        description: [
          { required: false, message: '请填写说明', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    titleName() {
      console.log(this.settingMode)
      const titleMap = {
        'addStepGoods': '商品溯源环节模版',
        'addStep': '环节'
      }
      return titleMap[this.settingMode]
    }
  },
  watch: {
    myIndex(val) {
      if (val === -1) {
        this.settingForm = {}
      } else {
        this.settingForm = Object.assign({}, this.dialogData)
      }
    }
  },
  mounted() {
    // if (this.settingMode === 'discount' || this.settingMode === 'membersRebate') {
    //   // this.getConstantPercent()
    //   this.getMomList()
    // }
  },
  methods: {
    // getMomList() {
    //   vipInfoAll().then(res => {
    //     if (res.code === '200') {
    //       this.momList = res.data
    //     } else {
    //       Message.error(res.message)
    //     }
    //   })
    // },
    submitForm(name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          // 向父级插件冒一个‘updataParent’ 的方法, 并且把填好的数据带过去， 到父级去做处理
          console.log(this.settingForm)
          // this.$emit('update:myIndex', -1)
          this.$emit('updataParent', this.settingForm)
          this.settingForm = {}
          this.$emit('update:settingsVisible', false)
        }
      })
    },
    closeDialog() {
      this.$emit('update:settingsVisible', false)
    }
  }
}
</script>
<style scope>
.bottomBtn{
    height: 80px;
    padding-top: 20px;
    width:100%;
    text-align: center;
    border-top: 1px solid #ddd
}
.bottomBtn button{
    display: inline-block;
}
select{
    width:100%
}
</style>
